home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1999 May / maximum-cd-1999-05.iso / Canvas 6 / DATA1.CAB / English_Tutorial_Files / Viewpage / Colada.class (.txt) next >
Encoding:
Java Class File  |  1998-11-04  |  9.6 KB  |  553 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.Frame;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.MediaTracker;
  9. import java.awt.Rectangle;
  10. import java.awt.image.ImageObserver;
  11. import java.net.MalformedURLException;
  12. import java.net.URL;
  13.  
  14. public class Colada extends Applet implements Runnable {
  15.    private String m_cvFile = new String();
  16.    public String m_cvFilePath;
  17.    public String m_bgTexture;
  18.    public String m_targetFrame;
  19.    private String m_status = new String("Done");
  20.    private boolean m_check;
  21.    private boolean m_upOrDwn;
  22.    public ColadaDoc m_colDoc;
  23.    private ColUrl m_curObj;
  24.    public Thread m_colada;
  25.    private int m_width;
  26.    private int m_height;
  27.    public Component m_comp = this;
  28.    public Thread m_colDocThread;
  29.    public Thread m_drawEngThread;
  30.    public boolean m_colDocDone;
  31.    public boolean m_colUpdtEnable;
  32.    public boolean m_urlLstDone;
  33.    public boolean firstDrawDone;
  34.    public boolean m_dloadStoped;
  35.    public boolean buttonisDn;
  36.    private boolean m_panOn;
  37.    public boolean m_stopCalled;
  38.    public boolean m_breakDrawAll;
  39.    private int mPosXdn;
  40.    private int mPosYdn;
  41.    // $FF: renamed from: a int
  42.    private int field_0;
  43.    private DrawEng drawEng;
  44.    public int numlayers;
  45.    public String layerFlags = new String();
  46.    public int numMediaObjs;
  47.    private Object[] mediaObs;
  48.    private boolean didNew;
  49.    private Image m_BackImg;
  50.    private MediaTracker tracker;
  51.  
  52.    public void stop() {
  53.       this.m_stopCalled = true;
  54.    }
  55.  
  56.    public void CallMediaObjects() {
  57.       boolean var1 = false;
  58.       if (!this.didNew && this.m_colUpdtEnable) {
  59.          this.mediaObs = new Object[this.numMediaObjs];
  60.          this.didNew = true;
  61.          ColObjIntr var2 = this.m_colDoc.m_drwLstHead;
  62.  
  63.          for(int var3 = 0; var2 != null; var2 = var2.getNext()) {
  64.             if (var2.getType() == 14) {
  65.                this.mediaObs[var3] = var2;
  66.                ++var3;
  67.             }
  68.          }
  69.       }
  70.  
  71.       if (this.m_colUpdtEnable && this.numMediaObjs > 0) {
  72.          for(int var4 = 0; var4 < this.numMediaObjs; ++var4) {
  73.             ColObj var5 = (ColObj)this.mediaObs[var4];
  74.             var5.EventProc((Event)null);
  75.          }
  76.       }
  77.  
  78.    }
  79.  
  80.    public void SetZoom(float var1) {
  81.       if (var1 >= 0.1F && var1 <= 5.0F) {
  82.          this.m_colDoc.m_colGraphicObj.m_magChck = var1;
  83.          ColGrph var10000 = this.m_colDoc.m_colGraphicObj;
  84.          var10000.m_xOrg += (float)this.m_colDoc.m_colGraphicObj.m_sx / this.m_colDoc.m_colGraphicObj.m_mag - (float)this.m_colDoc.m_colGraphicObj.m_sx / this.m_colDoc.m_colGraphicObj.m_magChck;
  85.          var10000 = this.m_colDoc.m_colGraphicObj;
  86.          var10000.m_yOrg += (float)this.m_colDoc.m_colGraphicObj.m_sy / this.m_colDoc.m_colGraphicObj.m_mag - (float)this.m_colDoc.m_colGraphicObj.m_sy / this.m_colDoc.m_colGraphicObj.m_magChck;
  87.          this.m_colDoc.m_colGraphicObj.m_mag = var1;
  88.          if (this.drawEng.inDrawAll) {
  89.             this.m_breakDrawAll = true;
  90.          }
  91.       }
  92.  
  93.       ((Component)this).repaint();
  94.    }
  95.  
  96.    public void TestFunc() {
  97.       Graphics var1 = ((Component)this).getGraphics();
  98.       var1.setColor(Color.red);
  99.       var1.fillRect(0, 0, 200, 200);
  100.    }
  101.  
  102.    public void paint(Graphics var1) {
  103.       Rectangle var2 = var1.getClipRect();
  104.       if (this.m_colDoc != null && this.m_colDoc.m_colGraphicObj != null) {
  105.          this.DrawBackGround(var1);
  106.          if (this.firstDrawDone) {
  107.             if (this.drawEng != null) {
  108.                this.drawEng.DoDrawAll(var2);
  109.                return;
  110.             }
  111.          } else {
  112.             this.m_colDoc.m_colGraphicObj.drawAll(var1);
  113.             this.firstDrawDone = true;
  114.          }
  115.  
  116.       }
  117.    }
  118.  
  119.    public String[][] getParameterInfo() {
  120.       String[][] var1 = new String[][]{{"cvwFile", "String", "Canvas 5.0 Flat File to view"}};
  121.       return var1;
  122.    }
  123.  
  124.    public void destroy() {
  125.       if (this.m_colada != null) {
  126.          if (this.m_drawEngThread != null) {
  127.             this.drawEng.StopWhile();
  128.             this.drawEng = null;
  129.             this.m_drawEngThread = null;
  130.          }
  131.  
  132.          if (this.m_colDocThread != null) {
  133.             this.m_colDoc.finalize();
  134.             this.m_curObj = null;
  135.             this.m_colDocThread.stop();
  136.             this.m_colDocThread = null;
  137.          }
  138.  
  139.          this.mediaObs = null;
  140.          this.m_comp = null;
  141.          this.m_colada.stop();
  142.          this.m_colada = null;
  143.       }
  144.  
  145.       System.gc();
  146.    }
  147.  
  148.    public void SendEventToObjType(Event var1, int var2, int var3, int var4, int var5) {
  149.       ColObjIntr var6 = this.m_colDoc.m_drwLstHead;
  150.  
  151.       for(boolean var7 = false; var6 != null; var6 = var6.getNext()) {
  152.          if (var6.getType() == var2) {
  153.             var7 = var6.EventProc(var1);
  154.          }
  155.  
  156.          if (var6.getType() == var3) {
  157.             var7 = var6.EventProc(var1);
  158.          }
  159.  
  160.          if (var6.getType() == var5) {
  161.             var7 = var6.EventProc(var1);
  162.          }
  163.  
  164.          if (((ColObj)var6).cvObjNum == (long)var4) {
  165.             var7 = var6.EventProc(var1);
  166.          }
  167.  
  168.          if (var7) {
  169.             break;
  170.          }
  171.       }
  172.  
  173.    }
  174.  
  175.    public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
  176.       return true;
  177.    }
  178.  
  179.    public void update(Graphics var1) {
  180.       this.paint(var1);
  181.    }
  182.  
  183.    public void DrawBackGround(Graphics var1) {
  184.       Rectangle var2 = var1.getClipRect();
  185.       if (this.m_BackImg == null) {
  186.          var1.setColor(this.m_colDoc.m_colGraphicObj.m_bkGrndClr);
  187.          var1.fillRect(var2.x, var2.y, var2.width, var2.height);
  188.       } else {
  189.          int var3 = this.m_BackImg.getWidth((ImageObserver)null);
  190.          int var4 = this.m_BackImg.getHeight((ImageObserver)null);
  191.          int var5 = 1;
  192.          int var6 = 1;
  193.          int var7 = 0;
  194.          int var8 = 0;
  195.          if (var3 < this.m_width) {
  196.             var5 = this.m_width / var3 + 1;
  197.          }
  198.  
  199.          if (var4 < this.m_height) {
  200.             var6 = this.m_height / var4 + 1;
  201.          }
  202.  
  203.          for(int var9 = var5; var6 > 0; --var6) {
  204.             while(var5 > 0) {
  205.                var1.drawImage(this.m_BackImg, var7, var8, var3, var4, (ImageObserver)null);
  206.                var7 += var3;
  207.                --var5;
  208.             }
  209.  
  210.             var8 += var4;
  211.             var7 = 0;
  212.             var5 = var9;
  213.          }
  214.  
  215.       }
  216.    }
  217.  
  218.    public void start() {
  219.       this.m_stopCalled = false;
  220.       if (this.m_colada == null) {
  221.          this.m_colada = new Thread(this);
  222.          this.m_colada.start();
  223.       }
  224.  
  225.       if (this.m_drawEngThread != null) {
  226.          this.m_drawEngThread.start();
  227.       } else if (this.m_colDoc != null) {
  228.          this.drawEng = new DrawEng(this, this.m_colDoc);
  229.          ++this.field_0;
  230.          this.m_drawEngThread = new Thread(this.drawEng);
  231.          this.m_drawEngThread.start();
  232.       }
  233.  
  234.       ((Component)this).repaint();
  235.    }
  236.  
  237.    public void SetLayerVisability(float var1, int var2) {
  238.       boolean var4 = var2 > 0;
  239.       int var5 = (int)var1;
  240.       if (var5 < this.numlayers) {
  241.          char[] var3 = this.layerFlags.toCharArray();
  242.          if (var4) {
  243.             var3[var5] = 'V';
  244.             ((Applet)this).showStatus("Showing Layer " + var5);
  245.          } else {
  246.             var3[var5] = 'H';
  247.             ((Applet)this).showStatus("Hidding Layer " + var5);
  248.          }
  249.  
  250.          this.layerFlags = new String(var3);
  251.       }
  252.  
  253.       ((Component)this).requestFocus();
  254.       ((Component)this).repaint();
  255.    }
  256.  
  257.    public int abs(int var1) {
  258.       if (var1 < 0) {
  259.          var1 *= -1;
  260.       }
  261.  
  262.       return var1;
  263.    }
  264.  
  265.    public void run() {
  266.       this.m_cvFile = ((Applet)this).getParameter("cvwFile");
  267.       this.m_cvFilePath = ((Applet)this).getParameter("cvwPath");
  268.       this.m_bgTexture = ((Applet)this).getParameter("bgTexture");
  269.       this.m_targetFrame = ((Applet)this).getParameter("targetFrame");
  270.       if (this.m_cvFilePath == null) {
  271.          this.m_cvFilePath = new String(((Applet)this).getCodeBase().toString());
  272.       }
  273.  
  274.       if (this.m_bgTexture != null) {
  275.          this.tracker = new MediaTracker(this);
  276.  
  277.          try {
  278.             this.m_BackImg = this.fetchImageAndWait(new URL(this.m_cvFilePath + this.m_bgTexture), 10);
  279.          } catch (Exception var5) {
  280.             this.m_BackImg = null;
  281.             ((Applet)this).showStatus("BackGround Load Error..");
  282.          }
  283.  
  284.          if (this.tracker.isErrorID(10)) {
  285.             this.m_BackImg = null;
  286.          }
  287.  
  288.          this.tracker = null;
  289.       }
  290.  
  291.       while(this.m_comp != null && !(this.m_comp instanceof Frame)) {
  292.          this.m_comp = this.m_comp.getParent();
  293.       }
  294.  
  295.       try {
  296.          ((Applet)this).showStatus("Downloading file, Please wait... 0% Done");
  297.          this.m_width = ((Component)this).size().width;
  298.          this.m_height = ((Component)this).size().height;
  299.          this.m_colDoc = new ColadaDoc(this, new URL(this.m_cvFilePath + this.m_cvFile));
  300.          this.m_colDocThread = new Thread(this.m_colDoc);
  301.          this.m_colDocThread.start();
  302.       } catch (Exception var4) {
  303.          ((Applet)this).showStatus("Error: " + "run Col. " + ((Throwable)var4).getMessage() + " occured while Downloading.");
  304.          this.stop();
  305.       }
  306.  
  307.       if (this.drawEng == null) {
  308.          try {
  309.             this.drawEng = new DrawEng(this, this.m_colDoc);
  310.             ++this.field_0;
  311.             this.m_drawEngThread = new Thread(this.drawEng);
  312.             this.m_drawEngThread.start();
  313.          } catch (Exception var3) {
  314.             ((Applet)this).showStatus("Error: " + "DrawEng Thread " + ((Throwable)var3).getMessage() + " occured while Downloading.");
  315.          }
  316.       }
  317.  
  318.       ((Component)this).requestFocus();
  319.       ((Component)this).repaint();
  320.    }
  321.  
  322.    public void SetPan(float var1, float var2) {
  323.       int var3 = (int)var1;
  324.       int var4 = (int)var2;
  325.       this.m_colDoc.m_colGraphicObj.m_xOrg = (float)var3;
  326.       this.m_colDoc.m_colGraphicObj.m_yOrg = (float)var4;
  327.       if (this.drawEng.inDrawAll) {
  328.          this.m_breakDrawAll = true;
  329.       }
  330.  
  331.       ((Component)this).repaint();
  332.    }
  333.  
  334.    Image fetchImageAndWait(URL var1, int var2) throws InterruptedException {
  335.       Image var3 = ((Applet)this).getImage(var1);
  336.       this.tracker.addImage(var3, var2);
  337.       this.tracker.waitForID(var2);
  338.       return var3;
  339.    }
  340.  
  341.    public boolean handleEvent(Event var1) {
  342.       boolean var2 = false;
  343.       if (this.m_urlLstDone) {
  344.          switch (var1.id) {
  345.             case 401:
  346.             case 403:
  347.                switch (var1.key) {
  348.                   case 27:
  349.                      if (!this.m_dloadStoped) {
  350.                         this.m_dloadStoped = true;
  351.                         this.m_colDocThread.suspend();
  352.                         ((Applet)this).showStatus("Download Suspended...");
  353.                         if (!this.m_colDocDone) {
  354.                            this.m_colDocDone = true;
  355.                         }
  356.                      } else {
  357.                         this.m_dloadStoped = false;
  358.                         this.m_colDocThread.resume();
  359.                      }
  360.                      break;
  361.                   case 43:
  362.                   case 61:
  363.                      if (this.m_colDocDone) {
  364.                         if (this.drawEng.inDrawAll) {
  365.                            this.m_breakDrawAll = true;
  366.                         }
  367.  
  368.                         this.m_colDoc.m_colGraphicObj.colZoom(0.25F);
  369.                         ((Component)this).repaint();
  370.                      }
  371.  
  372.                      var2 = true;
  373.                      break;
  374.                   case 45:
  375.                   case 95:
  376.                      if (this.m_colDocDone) {
  377.                         if (this.drawEng.inDrawAll) {
  378.                            this.m_breakDrawAll = true;
  379.                         }
  380.  
  381.                         this.m_colDoc.m_colGraphicObj.colZoom(-0.25F);
  382.                         ((Component)this).repaint();
  383.                      }
  384.  
  385.                      var2 = true;
  386.                      break;
  387.                   case 1000:
  388.                      if (this.m_colDocDone) {
  389.                         this.m_colDoc.m_colGraphicObj.colZoom(0.0F);
  390.                         if (this.drawEng.inDrawAll) {
  391.                            this.m_breakDrawAll = true;
  392.                         }
  393.  
  394.                         ((Component)this).repaint();
  395.                      }
  396.  
  397.                      var2 = true;
  398.                }
  399.             case 504:
  400.                ((Component)this).requestFocus();
  401.                ((Frame)this.m_comp).setCursor(0);
  402.                var2 = true;
  403.                break;
  404.             case 502:
  405.                this.SendEventToObjType(var1, 13, 16, -1, 14);
  406.                if (this.m_panOn) {
  407.                   this.m_colDoc.m_colGraphicObj.panOff();
  408.                   if (this.m_panOn) {
  409.                      if (this.drawEng.inDrawAll) {
  410.                         this.m_breakDrawAll = true;
  411.                      }
  412.  
  413.                      ((Component)this).repaint();
  414.                   }
  415.  
  416.                   this.m_panOn = false;
  417.                }
  418.  
  419.                this.m_upOrDwn = true;
  420.             case 501:
  421.                this.mPosXdn = var1.x;
  422.                this.mPosYdn = var1.y;
  423.             case 503:
  424.                this.SendEventToObjType(var1, 13, 0, -1, 0);
  425.                this.m_upOrDwn = false;
  426.                this.m_check = false;
  427.  
  428.                for(this.m_curObj = (ColUrl)this.m_colDoc.m_urlLstTail; this.m_curObj != null; this.m_curObj = (ColUrl)this.m_curObj.getPrev()) {
  429.                   if (this.m_curObj.m_poly.inside(var1.x, var1.y)) {
  430.                      if (var1.id == 502) {
  431.                         if (!this.m_curObj.m_url.regionMatches(true, 0, "mailto:", 0, 7) && !this.m_curObj.m_url.regionMatches(true, 0, "ftp", 0, 3) && !this.m_curObj.m_url.regionMatches(true, 0, "Http", 0, 4) && !this.m_curObj.m_url.regionMatches(true, 0, "www", 0, 3) && !this.m_curObj.m_url.regionMatches(true, this.m_curObj.m_url.length() - 3, "htm", 0, 3) && !this.m_curObj.m_url.regionMatches(true, this.m_curObj.m_url.length() - 4, "html", 0, 4)) {
  432.                            if (this.m_curObj.m_url.regionMatches(true, 0, "Play:", 0, 5) || this.m_curObj.m_url.regionMatches(true, 0, "Sound On:", 0, 9) || this.m_curObj.m_url.regionMatches(true, 0, "Sound Off:", 0, 10)) {
  433.                               int var10 = this.m_curObj.m_url.lastIndexOf(58);
  434.                               Long var4 = new Long(this.m_curObj.m_url.substring(var10 + 1));
  435.                               if (this.m_curObj.m_url.regionMatches(true, 0, "Sound Off:", 0, 10)) {
  436.                                  var1.key = 6969;
  437.                               } else if (this.m_curObj.m_url.regionMatches(true, 0, "Sound On:", 0, 9)) {
  438.                                  var1.key = 6970;
  439.                               } else {
  440.                                  var1.key = 6971;
  441.                               }
  442.  
  443.                               this.SendEventToObjType(var1, 0, 0, var4.intValue(), 0);
  444.                               Object var11 = null;
  445.                            }
  446.                         } else {
  447.                            try {
  448.                               ((Applet)this).showStatus(this.m_status = "connecting to " + this.m_curObj.m_url);
  449.                               if (this.m_targetFrame == null) {
  450.                                  ((Applet)this).getAppletContext().showDocument(new URL(this.m_curObj.m_url));
  451.                               } else {
  452.                                  ((Applet)this).getAppletContext().showDocument(new URL(this.m_curObj.m_url), this.m_targetFrame);
  453.                               }
  454.                               break;
  455.                            } catch (MalformedURLException var6) {
  456.                               ((Applet)this).showStatus("Bad URL " + "EventMouseMove " + ((Throwable)var6).getMessage());
  457.                            }
  458.                         }
  459.                      } else if (this.m_status.indexOf(this.m_curObj.m_url) < 0) {
  460.                         ((Frame)this.m_comp).setCursor(12);
  461.                         if (this.m_curObj.m_url.regionMatches(true, 0, "mailto:", 0, 7)) {
  462.                            ((Applet)this).showStatus(this.m_status = "Sends mail to " + this.m_curObj.m_url.substring(this.m_curObj.m_url.indexOf(":") + 1));
  463.                         } else if (!this.m_curObj.m_url.regionMatches(true, 0, "note:", 0, 5) && !this.m_curObj.m_url.regionMatches(true, 0, "Snd:", 0, 4)) {
  464.                            ((Applet)this).showStatus(this.m_status = "Shortcut to " + this.m_curObj.m_url);
  465.                         }
  466.                      }
  467.  
  468.                      this.m_check = true;
  469.                      break;
  470.                   }
  471.                }
  472.  
  473.                if (!this.m_check && this.m_status != "Done") {
  474.                   ((Frame)this.m_comp).setCursor(0);
  475.                   ((Applet)this).showStatus(this.m_status = "Done");
  476.                }
  477.  
  478.                var2 = false;
  479.                break;
  480.             case 505:
  481.                if (this.m_status != "Done") {
  482.                   ((Applet)this).showStatus(this.m_status = "Done");
  483.                }
  484.  
  485.                this.SendEventToObjType(var1, 13, 0, -1, 0);
  486.                var2 = true;
  487.                break;
  488.             case 506:
  489.                if (this.buttonisDn) {
  490.                   this.SendEventToObjType(var1, 13, 0, -1, 0);
  491.                } else if (((Component)this).inside(var1.x, var1.y) && (this.abs(this.mPosXdn - var1.x) > 3 || this.abs(this.mPosYdn - var1.y) > 3)) {
  492.                   if (!this.m_panOn) {
  493.                      this.m_colDoc.m_colGraphicObj.panOn(var1.x, var1.y);
  494.                      this.m_panOn = true;
  495.                   }
  496.  
  497.                   if (this.m_panOn) {
  498.                      Graphics var3 = ((Component)this).getGraphics();
  499.                      this.m_colDoc.m_colGraphicObj.panDrw(var1.x, var1.y);
  500.                      var3.setColor(this.m_colDoc.m_colGraphicObj.m_bkGrndClr);
  501.                      var3.fillRect(0, 0, 200, 18);
  502.                      var3.setColor(new Color(255 - this.m_colDoc.m_colGraphicObj.m_bkGrndClr.getRed(), 255 - this.m_colDoc.m_colGraphicObj.m_bkGrndClr.getGreen(), 255 - this.m_colDoc.m_colGraphicObj.m_bkGrndClr.getBlue()));
  503.                      var3.drawString("Delta X = " + (var1.x - this.mPosXdn) + " Delta Y = " + (var1.y - this.mPosYdn), 10, 10);
  504.                   }
  505.                } else if (this.m_panOn) {
  506.                   this.m_colDoc.m_colGraphicObj.panOff();
  507.                   this.m_panOn = false;
  508.                }
  509.  
  510.                var2 = true;
  511.          }
  512.       }
  513.  
  514.       if (!var2) {
  515.          var2 = super.handleEvent(var1);
  516.       }
  517.  
  518.       return var2;
  519.    }
  520.  
  521.    public void NewCVW(String var1) {
  522.       if (this.m_colDocThread != null) {
  523.          this.m_colDoc.finalize();
  524.          this.m_curObj = null;
  525.          this.m_colDocThread.stop();
  526.          this.m_colDocThread = null;
  527.       }
  528.  
  529.       this.mediaObs = null;
  530.       this.numMediaObjs = 0;
  531.       this.didNew = false;
  532.       this.m_colUpdtEnable = false;
  533.       this.firstDrawDone = false;
  534.       this.m_cvFile = var1;
  535.  
  536.       try {
  537.          ((Applet)this).showStatus("Downloading\tfile, Please wait... 0% Done");
  538.          this.m_width = ((Component)this).size().width;
  539.          this.m_height = ((Component)this).size().height;
  540.          ((Component)this).requestFocus();
  541.          this.m_colDoc = new ColadaDoc(this, new URL(this.m_cvFilePath + this.m_cvFile));
  542.          this.m_colDocThread = new Thread(this.m_colDoc);
  543.          this.m_colDocThread.start();
  544.       } catch (Exception var4) {
  545.          ((Applet)this).showStatus("Error: " + " NewCVW " + ((Throwable)var4).getMessage() + " occured while Downloading.");
  546.          this.stop();
  547.       }
  548.  
  549.       this.drawEng.m_theDoc = this.m_colDoc;
  550.       ((Component)this).repaint();
  551.    }
  552. }
  553.